<?php
/**
 * Die Klasse für die Fahrer.
 *
 * @author Timo
 */
class Driver
{
    protected $id               = 0;
    private   $team_id          = 0;
    protected $active           = false; // Nach der Anmeldung sind die Fahrer bzw. Teams sofort in der Serie. Müssen jedoch noch freigeschaltet bzw. akzeptiert werden.
    protected $joomla_id        = 0;
    protected $series           = '';
    protected $name             = 'Default Driver';
    private   $steam_name       = 'Steam-Account';
    private   $number           = 0;
    protected $points           = 0;
    protected $mulligan         = 0;
    protected $penalty_points   = 0;
    protected $races            = 0;
    private   $poles            = 0;
    protected $wins             = 0;
    protected $top5             = 0;
    private   $extra_weight_kg  = 0;

/**
 * Konstruktor der ggf. Statistiken lädt.
 * Hinweis: Sollte auf "False" gestellt werden,
 *          wenn man Aktionen durchführt, die
 *          sich nicht auf die Statistiken auswirken.
 *          Dadurch werden sie nicht erst unnötigerweise geladen.
 *
 * @author Timo
 */
    function Driver($name = 'Default Driver', $load = false)
    {
        $this->SetName($name);

        if($load)
        {
            $this->stats = new DriverStatistics();
            $this->stats->Load();
        }
    }

    public function SetTeamID($id)
    {
        if(is_integer($id))
        {
            $this->team_id = $id;
        }
        else
        {
            echo $id . ' is not an integer.';
        }
    }

    public function SetName($name)
    {
        if(is_string($name))
        {
            $this->name = $name;
        }
        else
        {
            echo $name . ' is not a string.';
        }
    }

    public function SetJID($joomla_id)
    {
        if(is_integer($joomla_id))
        {
            $this->joomla_id = $joomla_id;
        }
        else
        {
            echo $joomla_id . ' is not an integer.';
        }
    }

    public function SetNumber($number)
    {
        if(is_integer($number))
        {
            $this->number = $number;
        }
        else
        {
            echo $number . ' is not an integer.';
        }
    }

    public function SetSeries($series)
    {
        if(is_string($series))
        {
            $this->series = $series;
        }
        else
        {
          echo $series . ' is not a string.';
        }
    }

    public function SetPoints($points)
    {
        if(is_integer($points))
        {
            $this->points = $points;
        }
        else
        {
          echo $points . ' is not an integer.';
        }
    }

    public function SetPenaltyPoints($points)
    {
        if(is_integer($points))
        {
            $this->penalty_points = $points;
        }
        else
        {
          echo $points . ' is not an integer.';
        }
    }

    public function SetMulligan($mull)
    {
        if(is_integer($mull))
        {
            $this->mulligan = $mull;
        }
        else
        {
          echo $mull . ' is not an integer.';
        }
    }

    public function SetRaces($races)
    {
        if(is_integer($races))
        {
            $this->races = $races;
        }
        else
        {
          echo $races . ' is not an integer.';
        }
    }

    public function SetPoles($poles)
    {
        if(is_integer($poles))
        {
            $this->poles = $poles;
        }
        else
        {
          echo $poles . ' is not an integer.';
        }
    }

    public function SetWins($wins)
    {
        if(is_integer($wins))
        {
            $this->wins = $wins;
        }
        else
        {
          echo $wins . ' is not an integer.';
        }
    }

    public function SetTop5($top5)
    {
        if(is_integer($top5))
        {
            $this->$top5 = $top5;
        }
        else
        {
          echo $top5 . ' is not an integer.';
        }
    }

    public function SetExtraWeight($weight)
    {
        if(is_integer($weight))
        {
            $this->extra_weight_kg = $weight;
        }
        else
        {
          echo $weight . ' is not an integer.';
        }
    }

    public function SetSteamName($name)
    {
        if(is_integer($name))
        {
            $this->steam_name = $name;
        }
        else
        {
          echo $name . ' is not an integer.';
        }
    }

    public function GetTeamID()
    {
        return $this->team_id;
    }

    public function GetName()
    {
        return $this->name;
    }

    public function GetJID()
    {
        return $this->joomla_id;
    }

    public function GetNumber()
    {
        return $this->number;
    }

    public function GetPoints()
    {
        return $this->points;
    }

    public function GetPenaltyPoints()
    {
        return $this->penalty_points;
    }

    public function GetMulligan()
    {
        return $this->mulligan;
    }

    public function GetRaces()
    {
        return $this->races;
    }

    public function GetPoles()
    {
        return $this->poles;
    }

    public function GetWins()
    {
        return $this->wins;
    }

    public function GetTop5()
    {
        return $this->top5;
    }

    public function GetExtraWeight()
    {
        return $this->extra_weight_kg;
    }

    public function GetSteamName()
    {
        return $this->steam_name;
    }

/**
 * Daten aus der Datenbank abfragen..
 *
 * @author Timo
 */
    public function SyncDriverWithDB($series_shortcut)
    {
        require_once('Database/Database.php');

        $db        = new Database();
        $db->Connect();
        $driver_db = $series_shortcut . '_drivers';
        $condition = 'JID = ' . $this->joomla_id;
        $data      = $db->Select($driver_db, $condition);
        try
        {
            $this->active          = $data->Active;
            $this->id              = $data->ID_Driver;
            $this->team_id         = $data->Team_ID;
            $this->points          = $data->Points;
            $this->extra_weight_kg = $data->Extra_Weight_Kg;
            $this->mulligan        = $data->Mulligan;
            $this->name            = $data->Name;
            $this->penalty_points  = $data->Penalty_Points;
            $this->steam_name      = $data->Steam_Name;
            $this->races           = $data->Races;
            $this->wins            = $data->Wins;
            $this->poles           = $data->Poles;
            $this->top5            = $data->Top5;
        }
        catch(Exception $ex)
        {
            echo 'Syncing error: ' . $ex . '<br />';
        }
        $db->Disconnect();
    }
}
?>